<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Jedrzej\Pimpable\PimpableTrait;
use Illuminate\Database\Eloquent\SoftDeletes;

class ProductRelation extends Model
{
    use HasFactory;
    use PimpableTrait;
    use SoftDeletes;

    /**
     * 表中的类型状态
     */
    //参与的活动类型
    public $categoryTypeEnum = [
        'noActivity' => '普通商品',
        'seckill' => '秒杀',
        'bargain' => '砍价',
        'combination' => '拼团'
    ];

    /**
     * 可搜索字段
     */
    public $searchable = [
        'product_id',
        'user_id',
        'type',
        'category'
    ];

    /**
     * 可批量赋值字段
     */
    public $fillable = [
        'type'
    ];

    /**
     * 可排序字段
     */
    public $sortable = ['created_at', 'id'];

    /**
     * 默认排序字段
     */
    protected $defaultSortCriteria = ['id,desc'];


    /**
     * 关联的商品
     */
    function product(){
        return $this->belongsTo(Product::class,'product_id','id');
    }

    /**
     * 关联的用户
     */
    function user(){
        return $this->belongsTo(User::class,'user_id','id');
    }
}
